import math
import numpy as np
import pandas as pd


# 计算欧氏距离函数
# 参数为两个元组
def get_distance(t1, t2):
    distance = math.sqrt(np.power(t1[0] - t2[0], 2) + np.power(t1[1] - t2[1], 2))
    return distance


# 加载并初始化数据集(初始化为坐标点)
def load_txt_dataset(filepath, data_split='\t'):
    dataset = []
    with open(filepath) as f:
        # 对读到的每一行数据
        for line in f.readlines():
            curline = line.strip().split(data_split)  # strip()函数删掉换行符或空白符,split则是遇到对应符号就隔开
            fltline = list(map(float, curline))
            # 将拿到的小列表添加到大列表里面
            dataset.append(fltline)
    return dataset


def load_dataset(filepath, data_split='\t'):
    dataset = []
    with open(filepath) as f:
        # 对读到的每一行数据
        for line in f.readlines():
            curline = line.strip().split(data_split)  # strip()函数删掉换行符或空白符,split则是遇到对应符号就隔开
            fltline = list(map(float, curline))
            fltline = list([fltline[1], fltline[2]])
            # 将拿到的小列表添加到大列表里面
            dataset.append(fltline)
    return dataset


if __name__ == '__main__':
    dataset = load_dataset('E:\Pycharm_File\DBSCAN\Data\数据集\数据集\99_synthetic_dendrites.txt')
    print(dataset)
